#include "app_about_os.h"
#include "app_settings.h"
#if (LV_USE_FS_WIN32 == 1)
#include "../hal/hal_link.h"
#elif (LV_USE_FS_POSIX == 1)
#include "hal_link.h"
#endif

// 全局变量，存储 About OS 界面对象
static lv_obj_t *about_os_screen;

// 返回设置界面按钮点击事件处理函数
static void back_button_event_cb(lv_event_t *e)
{
    lv_obj_t *btn = lv_event_get_target(e);
    (void)btn;

    hal_link->buzz_di();
    
    // 以淡入动画效果切换回设置界面
    lv_scr_load_anim(settings_screen_get(), LV_SCR_LOAD_ANIM_FADE_ON, 200, 0, false);
}

static void show_os_img(void)
{
    // 创建一个容器
    lv_obj_t * container = lv_obj_create(about_os_screen);
    lv_obj_set_size(container, 350, 300);
    lv_obj_align(container, LV_ALIGN_LEFT_MID, 40, 0);
    // 清除容器的滚动标志，禁止滚动
    lv_obj_clear_flag(container, LV_OBJ_FLAG_SCROLLABLE);

    // 在容器内创建一个图片对象
    lv_obj_t * img = lv_img_create(container);
    lv_img_set_src(img, "A:./img/os_back.png");
    lv_obj_set_size(img, 350, 250);
    lv_obj_align_to(img, container, LV_ALIGN_TOP_MID, 0, -20);

    // 创建一个标签用于显示文字
    lv_obj_t * label = lv_label_create(img);
    lv_label_set_text(label, "Fuyb OS");
    lv_obj_align_to(label, container, LV_ALIGN_CENTER, -20, -20);

    // 初始化标签样式
    static lv_style_t style_label;
    lv_style_init(&style_label);

    // 设置标签文本颜色为白色
    lv_style_set_text_color(&style_label, lv_color_white());
    lv_style_set_text_font(&style_label, &lv_font_montserrat_26);
    lv_obj_add_style(label, &style_label, 0);

    lv_obj_t * labe_v = lv_label_create(container);
    lv_label_set_text(labe_v, "You System is update!");
    lv_obj_align_to(labe_v, container, LV_ALIGN_BOTTOM_LEFT, 0, 2);
}

static struct information_t
{
    char *str;
} information[] = {
    {"CPU:  Allwinner T113-S3"},
    {"MPU:  STM32H750CBT6"},
    {"RAM:  DDR3 128MB"},
    {"ROM:  Winbond Nand-Flash 128MB"},
    {"WIFI:  Realtek-RTL8723BS"},
    {"DISPLAY:  jlttek 854x480"},
};

static void show_information(void)
{
    // 初始化标签样式
    static lv_style_t style_label;
    lv_style_init(&style_label);

    // 设置标签文本颜色为白色
    lv_style_set_text_color(&style_label, lv_color_black());
    lv_style_set_text_font(&style_label, &lv_font_montserrat_20);

    lv_obj_t *last;
    for (uint8_t i = 0; i < sizeof(information) / sizeof(struct information_t); i++) {

        lv_obj_t * labe = lv_label_create(about_os_screen);
        lv_label_set_text(labe, information[i].str);
        
        lv_obj_add_style(labe, &style_label, 0);

        if (i == 0) {
            lv_obj_align(labe, LV_ALIGN_CENTER, 120, -120);
        } else {
            lv_obj_align_to(labe, last, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 30);
        }
        
        last = labe;
    }
}

// 创建 About OS 界面
void about_os_screen_init(void) 
{
    about_os_screen = lv_obj_create(NULL);

    show_return_base("About OS", about_os_screen, back_button_event_cb);

    show_os_img();

    show_information();
}

// 获取 About OS 界面对象
lv_obj_t *about_os_screen_get(void) 
{
    return about_os_screen;
}
/******************* (C) COPYRIGHT 2025 FUYEBING*****END OF FILE************/